package com.oms.system.service.impl;

import com.oms.system.domain.OmsDeptOrderStatus;
import com.oms.system.domain.OmsDeptOrderStatusExample;
import com.oms.system.mapper.OmsDeptOrderStatusMapper;
import com.oms.system.service.IOrderStatusDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("orderStatusDeptService")
public class OrderStatusDeptServiceImpl implements IOrderStatusDeptService {

    @Autowired
    private OmsDeptOrderStatusMapper deptOrderStatusMapper;

    @Override
    public Long insertStatus(OmsDeptOrderStatus deptOrderStatus) {
        deptOrderStatusMapper.insert(deptOrderStatus);
        return deptOrderStatus.getId();
    }

    @Override
    public void deleteStatus(Integer orderStatus, Long deptId) {
        OmsDeptOrderStatusExample example = new OmsDeptOrderStatusExample();
        OmsDeptOrderStatusExample.Criteria criteria = example.createCriteria();
        criteria.andDeptIdEqualTo(deptId);
        criteria.andOrderStatusEqualTo(orderStatus);
        deptOrderStatusMapper.deleteByExample(example);
    }

    @Override
    public void deleteById(Long id) {
        deptOrderStatusMapper.deleteByPrimaryKey(id);
    }

    @Override
    public OmsDeptOrderStatus getDeptStatusList(Long deptId, Integer orderStatus) {
        OmsDeptOrderStatusExample example = new OmsDeptOrderStatusExample();
        OmsDeptOrderStatusExample.Criteria criteria = example.createCriteria();
        criteria.andDeptIdEqualTo(deptId);
        criteria.andOrderStatusEqualTo(orderStatus);
        List<OmsDeptOrderStatus> list = deptOrderStatusMapper.selectByExample(example);
        if(list.size() > 0){
            return list.get(0);
        }else{
            return null;
        }
    }

    @Override
    public List<OmsDeptOrderStatus> getDeptList(Long deptId) {
        OmsDeptOrderStatusExample example = new OmsDeptOrderStatusExample();
        OmsDeptOrderStatusExample.Criteria criteria = example.createCriteria();
        criteria.andDeptIdEqualTo(deptId);
        return deptOrderStatusMapper.selectByExample(example);
    }
}
